package io.xccit.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.xccit.pojo.param.ShopCartSaveParam;
import io.xccit.pojo.param.ShopCartSelectParam;
import io.xccit.pojo.shopcart.Cart;
import io.xccit.pojo.vo.CartVO;
import io.xccit.result.AjaxResult;
import io.xccit.service.IShopCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author CH_ywx
 * @date 2023-09-18
 * @description
 */
@Api(tags = "购物车接口")
@RestController
@RequestMapping("/cart")
public class ShopCartController {

    @Autowired
    private IShopCartService shopCartService;

    @ApiOperation("商品添加至购物车")
    @PostMapping("/save")
    public AjaxResult save(@RequestBody ShopCartSaveParam shopCartSaveParam){
        return shopCartService.saveShopCart(shopCartSaveParam);
    }

    @ApiOperation("获取购物车列表")
    @PostMapping("/list")
    public AjaxResult list(@RequestBody ShopCartSelectParam shopCartSelectParam){
        return shopCartService.list(shopCartSelectParam.getUserId());
    }

    @ApiOperation("购物车数据更新")
    @PostMapping("/update")
    public AjaxResult update(@RequestBody Cart cart){
        System.out.println(cart);
        return shopCartService.update(cart);
    }

    @ApiOperation("购物车数据删除")
    @PostMapping("/remove")
    public AjaxResult remove(@RequestBody Cart cart){
        return shopCartService.delete(cart);
    }
}
